package ${serviceInterfacePackageName}.impl;

import com.alibaba.dubbo.config.annotation.Service;

import ${mapperPackageName}.${className}Mapper;
import ${packageName}.${className};
import ${serviceInterfacePackageName}.${className}Service;

import entity.PageResult;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**<#assign uncap_firstclassName = className?uncap_first/>
 *   ${uncap_firstclassName}
*  @Author ${author}
*  @Email ${email}
*  @Date ${date?string("yyyy-MM-dd HH:mm:ss")}
*/
@Service(timeout = 4000)
@Transactional
public class ${className}ServiceImpl implements ${className}Service {

    @Autowired
    private ${className}Mapper ${className?uncap_first}Mapper;
    /**
    * 查询所有
    * @return List<${className}>
    */
    @Override
    public List<${className}> findAll() {
        return ${className?uncap_first}Mapper.selectAll();
    }
    /**
    * ${className}分页
    * @param pageNum 当前页面
    * @param pageSize 每页记录数
    * @return
    */
    @Override
    public PageResult findPage(int pageNum, int pageSize) {
        //开启分页插件功能
        PageHelper.startPage(pageNum,pageSize);

        Page<${className}> page = (Page<${className}>)${className?uncap_first}Mapper.selectAll();

        return new PageResult(page.getTotal(),page.getResult());
    }
    /**
    * ${className}条件分页
    * @param ${className?uncap_first} 查询条件
    * @param pageNum 当前页面
    * @param pageSize 每页记录数
    * @return
    */
    @Override
    public PageResult findPage(${className} ${className?uncap_first}, int pageNum, int pageSize) {
        //开启分页插件功能
        PageHelper.startPage(pageNum,pageSize);

        Page<${className}> page = (Page<${className}>)${className?uncap_first}Mapper.selectBySelective(${className?uncap_first});

        return new PageResult(page.getTotal(),page.getResult());
    }

    /**
    * 添加${className}
    * @param ${className?uncap_first}
    * @return
    */
    @Override
    public void add(${className} ${className?uncap_first}) {
        ${className?uncap_first}Mapper.insert(${className?uncap_first});
    }
    /**
    * 删除${className}
    * @param ids
    * @return
    */
    @Override
    public void del(Long[] ids) {

        for (Long id:ids) {
            ${className?uncap_first}Mapper.deleteByPrimaryKey(id);
        }
    }
    /**
    * 查询一个${className}
    * @param id
    * @return
    */
    @Override
    public ${className} findOne(Long id) {
        return ${className?uncap_first}Mapper.selectByPrimaryKey(id);
    }
    /**
    * 修改
    * @param ${className?uncap_first}
    * @return
    */
    @Override
    public void update(${className} ${className?uncap_first}) {
        ${className?uncap_first}Mapper.updateByPrimaryKey(${className?uncap_first});
    }
}
